package com.itheima.service.impl;

import com.itheima.jopo.Emp;
import com.itheima.mapper.EmpMapper;
import com.itheima.service.EmpService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * EmpServiceImpl
 *
 * @author liliudong
 * @version 1.0
 * @description
 * @date 2023/4/28 13:00
 */
@Service
public class EmpServiceImpl implements EmpService {

    private final EmpMapper empMapper;

    /**
     * 这里采用构造器注入
     *
     * @param empMapper
     */
    public EmpServiceImpl(EmpMapper empMapper) {
        this.empMapper = empMapper;
    }

    @Override
    public boolean existByUsername(String username) {
        return empMapper.selectCountByUsername(username) > 0;
    }

    @Override
    public void saveOne(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        emp.setCreateTime(LocalDateTime.now());
        empMapper.insertOne(emp);
    }

    @Override
    public void removeById(String id) {
        empMapper.deleteById(id);
    }

    @Override
    public void updateById(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.updateById(emp);
    }

    @Override
    public List<Emp> queryList() {
        return empMapper.selectList();
    }

    @Override
    public Emp queryById(String id) {
        return empMapper.selectById(id);
    }
}
